app.factory('adBuy',[function(){
	var obj = {state: false};
	obj.data = {};
	
	obj.addCar = function(i,text){
		obj.state = true;
		i.text = text || '热销榜';
		obj.data[i.text+''+i.id] = i;
		i.state=true;
		
		if(i.num==0){
			delete obj.data[i.text+''+i.id]
			var flag = true;
			for(var i in obj.data){
				flag = false;
			}
			if(flag){
				obj.state = false;
			}
		}
	}
	return obj;
	
	
}])

.factory('selectService',['adBuy',function(adBuy){
	var obj = {};
	obj.selectAll = function  (state) {
		for(var i in adBuy.data){
			adBuy.data[i].state = state;
		}
	}
	
	obj.selectFn = function(){
		var _state = true;
		for(var i in adBuy.data){
			if(!adBuy.data[i].state){
				_state = false;
			}
		}
		return _state;
	}
	
	
	return obj;
}])

.factory("count",["adBuy",function(adBuy){
	var obj = {};
	obj.count = 0;
	obj.countFn = function(){
		var count = 0;
		for(var i in adBuy.data){
			count += adBuy.data[i].num;
		}
		obj.count = count;
	}
	return obj;
}])